﻿
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>JueSeAdd</title>

    <link href="~/layui-v2.6.8/layui/css/layui.css" rel="stylesheet" />
    <script src="~/layui-v2.6.8/layui/layui.js"></script>
    <script src="~/lib/jquery/dist/jquery.js"></script>
</head>
<body>

    <form class="layui-form" action="" id="AddForm">
        <div class="layui-form-item">
            <label class="layui-form-label">角色名称</label>
            <div class="layui-input-block">
                <input type="text" name="Jname" id="Jname" lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-block">
                <input type="text" name="Jnum" id="Jnum" lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">备注</label>
            <div class="layui-input-block">
                <input type="text" name="Jinfou"  id="Jinfou" lay-verify="title" autocomplete="off" placeholder="请输入标题" class="layui-input">
            </div>
        </div>


        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="submit" class="layui-btn" lay-submit="" lay-filter="demo1">立即添加</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
        </div>

    </form>

    <!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->
    <script>
        layui.use(['form', 'layedit', 'laydate'], function () {
            var form = layui.form
                , layer = layui.layer
                , layedit = layui.layedit
                , laydate = layui.laydate;
            //创建一个编辑器
            var editIndex = layedit.build('LAY_demo_editor');
            //监听指定开关
            form.on('switch(switchTest)', function (data) {
                layer.msg('开关checked：' + (this.checked ? 'true' : 'false'), {
                    offset: '6px'
                });
                layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
            });
            //监听提交
            form.on('submit(demo1)', function (data) {
                //添加
                $.ajax({
                    url: 'http://localhost:36862/api/JuSe/JuSerAdd',
                    data: $("#AddForm").serialize(),
                    type: 'post',
                    success: function (d) {
                        if (d > 0)
                        {
                            layer.msg('添加成功', { time: 2000, icon: 1 }, function () {
                                parent.location.href = '/JueSe/JueSeShow';
                            })
                        }
                        else
                        {
                            layer.msg('添加失败!', { time: 2000, icon: 5 }, function () {
                                parent.location.href = '/JueSe/JueSeShow';
                            })
                        }
                    }
                })
                return false;
            });
            //表单赋值
            layui.$('#LAY-component-form-setval').on('click', function () {
                form.val('example', {
                    "username": "贤心" // "name": "value"
                    , "password": "123456"
                    , "interest": 1
                    , "like[write]": true //复选框选中状态
                    , "close": true //开关状态
                    , "sex": "女"
                    , "desc": "我爱 layui"
                });
            });

            //表单取值
            layui.$('#LAY-component-form-getval').on('click', function () {
                var data = form.val('example');
                alert(JSON.stringify(data));
            });

        });
    </script>


</body>
</html>
